import 'dart:io';

class KL_keralaLottoModel {
  /*\
  "id": 11,
            "game_name": "FIFTY-FIFTY",
            "draw_code": "FF-120",
            "ticket_prefix": "F",
            "draw_datetime": "2024-12-11 20:30:00",
            "draw_datetime_utc": "2024-12-11 15:00:00",
            "venue": "GORKY BHAVAN,  NEAR BAKERY JUNCTION, THIRUVANANTHAPURAM",
            "prizes": 
  */
  int? id;
  var game_name;
  var draw_code;
  var ticket_prefix;
  var draw_datetime;
  var draw_datetime_utc;
  var venue;
  List? prizes;

  KL_keralaLottoModel({
    this.id,
    this.game_name,
    this.draw_code,
    this.ticket_prefix,
    this.draw_datetime,
    this.draw_datetime_utc,
    this.venue,
    this.prizes,
  });
  KL_keralaLottoModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    game_name = json['game_name'];
    draw_code = json['draw_code'];
    ticket_prefix = json['ticket_prefix'];
    draw_datetime = json['draw_datetime'];
    draw_datetime_utc = json['draw_datetime_utc'];
    venue = json['venue'];
    prizes = _configPrizes(json['prizes']);
  }

  _configPrizes(Map<String, dynamic> prizes) {
    List prizeModels = [];
    List<String> keys = prizes.keys.toList();
    // 找到 'Cons' 的索引
    int index = keys.indexOf('Cons');
    if (index != -1) {
      // 移除 'Cons'
      String consItem = keys.removeAt(index);
      // 将 'Cons' 插入到第二个位置（索引 1）
      keys.insert(1, consItem);
    }

    for (var key in keys) {
      var prize = prizes[key];
      if (prize != null) {
        var prizeModel = PrizeModel.fromJson(prize);
        prizeModels.add(prizeModel);
      }
    }
    return prizeModels;
  }
}

class PrizeModel {
  /*
  "rank_title": "1st",
                    "prize_amount": "10000000.00",
                    "ticket_numbers": [
                        "FP701324"
                    ]
  */
  var rank_title;
  var prize_amount;
  List? ticket_numbers;

  PrizeModel({
    this.rank_title,
    this.prize_amount,
    this.ticket_numbers,
  });
  PrizeModel.fromJson(Map<String, dynamic> json) {
    rank_title = json['rank_title'];
    prize_amount = json['prize_amount'];
    ticket_numbers = json['ticket_numbers'] ?? [];
  }
}

class NextDrawModel {
  /*
  "game_name": "KARUNYA PLUS",
        "draw_code": "KN-551",
        "ticket_prefix": "P",
        "draw_datetime": "2024-12-12 20:30:00",
        "draw_datetime_utc": "2024-12-12 15:00:00"
  */
  var game_name;
  var draw_code;
  var ticket_prefix;
  var draw_datetime;
  var draw_datetime_utc;
  var playable_text;
  var link;
  bool playable;

  NextDrawModel({
    this.game_name,
    this.draw_code,
    this.ticket_prefix,
    this.draw_datetime,
    this.draw_datetime_utc,
    this.playable_text,
    this.link,
    this.playable = false,
  });
  NextDrawModel.fromJson(Map<String, dynamic> json)
      : playable = json['playable'] ?? false {
    game_name = json['game_name'];
    draw_code = json['draw_code'];
    ticket_prefix = json['ticket_prefix'];
    draw_datetime = json['draw_datetime'];
    draw_datetime_utc = json['draw_datetime_utc'];
    playable_text = json['playable_text'];
    link = json['link'];
  }
}
